package com.molichuxing.services.business.service.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.molichuxing.services.business.convertor.Convert;
import com.molichuxing.services.business.dto.request.create.OrderRenewCreateBizDto;
import com.molichuxing.services.business.service.OrderRenewBizService;
import com.molichuxing.services.infrastructure.dto.request.create.OrderCreateDto;
import com.molichuxing.services.infrastructure.service.OrderService;
import com.molichuxing.services.infrastructure.service.OrderStatusFlowService;
import com.molichuxing.services.infrastructure.service.OrderSubscribeService;
import com.molichuxing.services.property.OrderTypeEnum;
import com.molichuxing.services.utils.OrderUtil;

/**
 * 续订订单组合服务
 * 
 * @author zoumingyu
 * @date 2019年9月26日
 *
 */
@Service("orderRenewBizService")
public class OrderRenewBizServiceImpl implements OrderRenewBizService {
	private static final Logger logger = LoggerFactory.getLogger(OrderRenewBizServiceImpl.class);

	@Resource
	private OrderSubscribeService orderSubscribeService;

	@Resource
	private OrderService orderService;

	@Resource
	private OrderStatusFlowService orderStatusFlowService;

	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
	public Long ceateRenew(OrderRenewCreateBizDto createDto) {
		// 订单号
		Long orderCode = OrderUtil.getOrderCode();
		// 新增订单表信息
		orderService.create(new OrderCreateDto(orderCode, OrderTypeEnum.SUBSCRIBE));
		// 新增订阅里程订单
		orderSubscribeService.create(Convert.toOrderSubscribeCreateDto(orderCode, createDto));
		// 新增订单流转信息
		orderStatusFlowService.createOrderStatusFlow(Convert.toOrderStatusFlowCreateDto(orderCode, createDto));

		return orderCode;
	}

}
